package com.camerareader.mvp.main_page;

import android.app.Activity;
import android.mtp.MtpObjectInfo;
import android.util.Log;
import android.widget.ImageView;

import com.usbconnecter.MtpInfoInterface;
import com.usbconnecter.UsbConnector;

import java.util.ArrayList;
import java.util.List;

/**
 * Created by Administrator on 2016-12-06.
 */

class MainActivityPresenter implements MainActivityContract.Presenter{
    private final String TAG = "MainActivityPresenter";

    private UsbConnector usbConnector;
    private MainActivityContract.View mView;

    @Override
    public void onCreate(final MainActivityContract.View mView) {
        this.mView = mView;
        usbConnector = new UsbConnector((Activity)mView, new MtpInfoInterface() {
            @Override
            public void onContentListReady(ArrayList<MtpObjectInfo> list) {
                mView.setImageList(list);
            }

            @Override
            public void onStart() {
                mView.setLoadingProgress(true);
            }

            @Override
            public void onDeleteProgress(int progress, int total) {

            }

            @Override
            public void onSaveProgress(int index, int total, boolean success) {
                Log.w(TAG, "保存图片成功。。。。 " + index + "  " + success);
                mView.setSaveResponse(index, total, success);
            }

            @Override
            public void onSaveCompleted() {
                mView.onSaveCompleted();
            }

            @Override
            public void onDeleteComplete() {

            }
        });
    }

    @Override
    public void onDestroy() {
        usbConnector.onDestroy();
    }

    @Override
    public void startScan() {
        usbConnector.startScan();
    }

}
